package com.dragon.repository.mapper;

import com.dragon.repository.entity.Announcement;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 公告表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-07-26
 */
@Mapper
public interface AnnouncementMapper extends BaseMapper<Announcement> {

    @Update("UPDATE  dragon_announcement a  " +
            "SET a.`status` = CASE STATUS WHEN 0 THEN 1 WHEN 1 THEN 0 END WHERE a.id = #{id}")
    void changeStatus(Integer id);

    @Select("SELECT a.* FROM dragon_announcement a WHERE a.status = 0 ORDER BY a.create_time DESC LIMIT 1")
    Announcement getLatestOne();
}
